from rest_framework import serializers

from goods.models import CategoryVisitCount, GoodsCategory

#1,分类访问量序列化器
from users.models import User


class UserGoodsDayCountSerializer(serializers.ModelSerializer):
    category = serializers.StringRelatedField(read_only=True)
    class Meta:
        model = CategoryVisitCount
        fields = "__all__"
        
        
#2,用户序列化器

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        # fields = "__all__"
        fields = ["id", "username", "mobile", "email","password"]

        # 指定密码进行反序列化,不进行序列化
        extra_kwargs = {
            "password": {
                "write_only": True
            }
        }

    # 1,重写create方法,密码加密
    def create(self, validated_data):

        return User.objects.create_user(**validated_data)



#2,sku分类数据
class SKUCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = "__all__"